
import { _decorator, Component, Node,Graphics, EventMouse,director  } from 'cc';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = Star
 * DateTime = Fri Apr 15 2022 20:33:28 GMT+0800 (中国标准时间)
 * Author = xiaopang125
 * FileBasename = Star.ts
 * FileBasenameNoExtension = Star
 * URL = db://assets/Star.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */
 
@ccclass('Star')
export class Star extends Component {
    // [1]
    // dummy = '';

    // [2]
    // @property
    // serializableDummy = 0;

 

    public starClor='';

    start () {

        this.starClor=this.color16();

        this.drawStar(this.starClor);
        this.node.on(Node.EventType.TOUCH_START,this.starClick,this)
        // [3]
    }

    private drawStar(fillColor){
        const g = this.getComponent(Graphics);
        g.lineWidth = 10;
        g.fillColor.fromHEX(fillColor);
        g.moveTo(-40, -40);
        g.quadraticCurveTo(-42,-37,-45,-35);
        g.lineTo(-45, 40);
        g.quadraticCurveTo(-42,37,-40,45);
        g.lineTo(40, 45);
        g.quadraticCurveTo(42,37,45,40);
        g.lineTo(45, -35);
        g.quadraticCurveTo(42,-37,40,-40);
        // g.lineTo(-40, 0);

        // g.close();
        g.stroke();
        g.fill();
        
    }
    private starClick(){
        console.log("click,this.starClor=",this.starClor);

console.log("click,this.findClor=",this.node.parent.getComponent("gameInt").findClor);
        if(this.node.parent.getComponent("gameInt").findClor==this.starClor){

            this.node.destroy();
            num++;
           
            
        }else{
            num=0;
           
        }

        director.loadScene("scene");
    }
    private color16(){//十六进制颜色随机

        var r = Math.floor(Math.random()*256);
        var g = Math.floor(Math.random()*256);
        var b = Math.floor(Math.random()*256);
        var color1 = '#'+r.toString(16)+g.toString(16)+b.toString(16);
        return color1;
    }

    // update (deltaTime: number) {
    //     // [4]
    // }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/decorator.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
 */
